﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Data;

namespace System.Windows
{
    public static class DependencyObjectExtensions
    {
        public static void UpdateTarget(this DependencyObject obj, DependencyProperty dp)
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                BindingOperations.GetBindingExpressionBase(obj, dp)?.UpdateTarget();
            });
        }

        public static void UpdateTarget(this ItemsControl c)
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                var itemsView = CollectionViewSource.GetDefaultView(c.ItemsSource);
                itemsView.Refresh();
            });
        }
    }
}
